package com.community.backend.controller;

import com.community.backend.pojo.Property;
import com.community.backend.pojo.Security;
import com.community.backend.pojo.dto.PropertyQueryDTO;
import com.community.backend.service.PropertyService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/*
物业
 */
@Slf4j
@RestController
@RequestMapping("/property")
public class PropertyController {
    private final PropertyService propertyService;

    public PropertyController(PropertyService propertyService) {
        this.propertyService = propertyService;
    }

    @GetMapping("/page")
    public Result<PageResult> propertyByPage( PropertyQueryDTO propertyQueryDTO) {
        log.info("安保分页信息：{}", propertyQueryDTO);
        // 设置默认值
        PageResult pageResult = propertyService.propertyByPage(propertyQueryDTO);
        return Result.success(pageResult);
    }

    @PutMapping("/resetPwd/{id}")
    public Result resetPwd(@PathVariable String id) {
        Property property = new Property();
        property.setId(id);
        property.setPassword("123456");
        propertyService.update(property);
        return Result.success();
    }
    @PutMapping
    public Result propertyUpdate(@RequestBody Property property) {
         propertyService.update(property);
         return Result.success("更新成功");
    }
    //重置密码
//    @PutMapping("/resetPwd/{id}")
//    public Result resetPwd(@PathVariable Integer id) {
//        Security security = new Security();
//        security.setId(id);
//        security.setPassword("123456");
//        return securityService.updateById(security);
//    }
    @DeleteMapping("/{id}")
    public Result propertydeleteById(@PathVariable String id) {
         propertyService.deleteById(id);
         return Result.success("删除成功");
    }
    @PostMapping
    public Result propertyAdd(@RequestBody Property property) {
        System.out.println("添加人员信息："+ property);
         propertyService.addProperty(property);
         return Result.success("添加成功");
    }
}
